package com.ziyun.pop.rest.module.seller;

import com.service.goods.model.seller.RegisterSellerParamDto;
import com.ziyun.pop.common.utils.UserUtils;
import com.ziyun.pop.modules.supp.service.SellerInfoService;
import com.ziyun.pop.modules.supp.vo.SellerInfoApiVo;
import com.ziyun.pop.modules.supp.vo.SellerTodayApiVo;
import com.ziyun.pop.modules.supp.vo.ShopVo;
import io.renren.common.utils.R;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 商户信息服务
 * @author gaosheng
 * @date 2019-01-03 15:30
 */
@Api(value = "SellerRestApi", tags = "商户信息服务")
@RestController
@RequestMapping("popApi/seller")
public class SellerRestApi {

    @Autowired
    private SellerInfoService sellerInfoService;

    @ApiOperation(value = "查询商户信息", notes = "")
    @ApiResponses(value = @ApiResponse(code = 200, message = "获取成功", response = SellerInfoApiVo.class))
    @GetMapping("/getSellerInfo")
    public R getSellerInfo(){
        Long sellerId = UserUtils.getCurentUser().getSellerId();
        return sellerInfoService.getSellerInfo(sellerId);
    }

    @ApiOperation(value = "查询商户统计数据信息", notes = "")
    @ApiResponses(value = @ApiResponse(code = 200, message = "获取成功", response = ShopVo.class))
    @GetMapping("/getSellerData")
    public R getSellerData(){
        Long sellerId = UserUtils.getCurentUser().getSellerId();
        return sellerInfoService.getSellerData(sellerId);
    }

    @ApiOperation(value = "查询商户今日订单、访客、成交额信息", notes = "")
    @ApiResponses(value = @ApiResponse(code = 200, message = "获取成功", response = SellerTodayApiVo.class))
    @GetMapping("/getSellerTodayData")
    public R getSellerTodayData(){
        Long sellerId = UserUtils.getCurentUser().getSellerId();
        return sellerInfoService.getSellerTodayData(sellerId);
    }

    @ApiOperation(value = "商户注册")
    @ApiResponses(value = @ApiResponse(code = 200, message = "商户注册成功"))
    @ApiImplicitParam(name = "registerSellerParamDto", value = "商户注册参数", required = true, dataType = "RegisterSellerParamDto")
    @PostMapping("/registerSeller")
    public R registerSeller(@RequestBody RegisterSellerParamDto registerSellerParamDto){
        return sellerInfoService.registerSeller(registerSellerParamDto);
    }

    @ApiOperation(value = "设置银行卡")
    @ApiResponses(value = @ApiResponse(code = 200, message = "设置成功"))
    @ApiImplicitParam(name = "params", value = "设置银行卡参数", required = true, paramType = "body")
    @PostMapping("bindBankCard")
    public R bindBankCard(@RequestBody Map<String,Object> params) {
        Long sellerId = UserUtils.getCurentUser().getSellerId();
       return sellerInfoService.bindBankCard(params.get("receiverName").toString(),params.get("receiverCredential").toString(),params.get("receiverAccount").toString(),params.get("receiverAccountBranch").toString(),sellerId);
    }

    @ApiOperation(value = "获取银行卡信息")
    @ApiResponses(value = @ApiResponse(code = 200, message = "获取成功"))
    @GetMapping("bankCard")
    public R bankCard() {
        Long sellerId = UserUtils.getCurentUser().getSellerId();
        return sellerInfoService.bankCard(sellerId.intValue());
    }

}
